<?php

include_once './utils/conn.php';

//get user input

$query=$_POST["query"];

//write sql

$sql="select * from student where stu_no='".$query."' || stu_name like '%".$query."%' || sex='".$query;
$sql.="' || major like '%".$query."%' ||  class_name like '%".$query."%' || tel ='".$query."' || hobby like '%".$query."%'";

//execute sql
$result=mysqli_query($conn,$sql);
$data=[];
//遍历结果集,保存到数组中
while($row=mysqli_fetch_assoc($result)){
    $data[]=["stu_no"=>$row["stu_no"],
    "stu_name"=>$row["stu_name"],
    "sex"=>$row["sex"],
    "tel"=>$row["tel"]
    ,"major"=>$row["major"],
    "class_name"=>$row["class_name"],
    "hobby"=>$row["hobby"]];
}
echo json_encode(["code"=>1,"msg"=>"数据查询成功","data"=>$data],JSON_UNESCAPED_UNICODE);